Skip to content

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Mar 30, 2023

Fixes an issue with the new solver where reporting a borrow-checker error ICEs because it calls InferCtxt::evaluate_obligation.

This also removes a handful of unnecessary tcx.infer_ctxt().build() calls that are only there to mitigate this same exact issue, but with the old solver.

Fixes compiler-errors/next-solver-hir-issues#12.


This implements @aliemjay's solution where we just don't take the region constraints, but clone them. This potentially makes it easier to write a bug about taking region constraints twice or never at all, but again, not many folks are touching this code.

@rustbot
Copy link
Collaborator

rustbot commented Mar 30, 2023

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 30, 2023
@compiler-errors
Copy link
Member Author

Grr, meant to r? @ghost for now.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

r=me afterwards

.as_mut()
.expect("region constraints already solved")
// Replace region constraints if they've been taken.
// This should only happen on an error path, so delay a bug.
Copy link
Contributor

@lcnr lcnr Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This should only happen on an error path, so delay a bug.
// This should only happen on an error path, so delay a bug.
//
// This is only allowed so one can use the existing inference
// context for diagnostics.

Comment on lines 232 to 237
.get_or_insert_with(|| {
ty::tls::with(|tcx| {
tcx.sess.delay_span_bug(DUMMY_SP, "region constraints already solved");
});
RegionConstraintStorage::default()
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think RegionConstraintStorage::default() is a sane value. This resets the region variables counter and thus nullifies the whole point of using the existing InferCtxt.

How about changing InferCtxt::take_region_var_origins to clone region VarInfos instead of removing them? and probably using better name for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can keep it named take_ name, but set some flag that the infos have been taken, and delay a bug if we try to take them again or try to borrow them again?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm, I have no strong opinion here, but I don't like delaying a bug in InferCtxt. I prefer the code there to be independent from the compilation session as much as possible.

Changing take_region_var_infos is unfortunate as it would no longer guard against future addition of region constraints, but I think it's the best option here given that it's used only once in borrowck and we don't expect users of InferCtxt to implement their own region resolution.

@bors
Copy link
Collaborator

bors commented Apr 3, 2023

☔ The latest upstream changes (presumably #109849) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-cloud-vms rust-cloud-vms bot force-pushed the replenish-region-constraints branch from 4e1c9b3 to 08101d6 Compare April 16, 2023 19:32
@compiler-errors
Copy link
Member Author

Ok, took the alternative approach.

@rustbot ready

@compiler-errors compiler-errors marked this pull request as ready for review April 16, 2023 19:33
@rust-cloud-vms rust-cloud-vms bot force-pushed the replenish-region-constraints branch from 08101d6 to 3d604ea Compare April 16, 2023 19:44
/// `resolve_regions_and_report_errors` is invoked, this gets set to `None`
/// -- further attempts to perform unification, etc., may fail if new
/// region constraints would've been added.
region_constraint_storage: Option<RegionConstraintStorage<'tcx>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth keeping this Option and clearing it in InferCtxt::{resolve_regions,skip_region_resolution} . This way limit this hack to MIR borrowck, rather that lexical region resolver which is more commonly used.

Copy link
Member

@aliemjay aliemjay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r? @aliemjay
looks good. r=me with or without the previous nit.

@rust-cloud-vms rust-cloud-vms bot force-pushed the replenish-region-constraints branch from 3d604ea to 72ffa11 Compare April 17, 2023 16:44
@compiler-errors compiler-errors changed the title Replace region constraints if InferCtxt::probe is called after resolve_regions Clone region var origins instead of taking them in borrowck Apr 17, 2023
@compiler-errors
Copy link
Member Author

Ok, changed it back to Option.

@bors r=aliemjay

@bors
Copy link
Collaborator

bors commented Apr 17, 2023

📌 Commit 72ffa1160aab7b92a20260c3bbe651119935952e has been approved by aliemjay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 17, 2023
@bors
Copy link
Collaborator

bors commented Apr 17, 2023

☔ The latest upstream changes (presumably #110458) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 17, 2023
@rust-cloud-vms rust-cloud-vms bot force-pushed the replenish-region-constraints branch from 72ffa11 to 964600b Compare April 21, 2023 00:41
@compiler-errors
Copy link
Member Author

Rebased

@bors r=aliemjay

@bors
Copy link
Collaborator

bors commented Apr 21, 2023

📌 Commit 964600b has been approved by aliemjay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 21, 2023
@bors
Copy link
Collaborator

bors commented Apr 22, 2023

⌛ Testing commit 964600b with merge 4396cec...

@bors
Copy link
Collaborator

bors commented Apr 22, 2023

☀️ Test successful - checks-actions
Approved by: aliemjay
Pushing 4396cec to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 22, 2023
@bors bors merged commit 4396cec into rust-lang:master Apr 22, 2023
@rustbot rustbot added this to the 1.71.0 milestone Apr 22, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4396cec): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.5% [0.5%, 0.5%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [0.5%, 0.5%] 1

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.2% [1.2%, 1.2%] 1
Improvements ✅
(primary)
-2.5% [-2.5%, -2.5%] 1
Improvements ✅
(secondary)
-2.4% [-2.8%, -2.0%] 4
All ❌✅ (primary) -2.5% [-2.5%, -2.5%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.3% [-2.3%, -2.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.3% [-2.3%, -2.3%] 1

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 6, 2023
…r=compiler-errors

Fix comment for `get_region_var_origins`

rust-lang#109753 changed the logic but not the comment.

r? `@compiler-errors`
@compiler-errors compiler-errors deleted the replenish-region-constraints branch August 11, 2023 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Evaluation probe in new solver causes ICE in late borrowck
7 participants